// var cluster = require('cluster');
// var http = require('http');
// var numCPUs = require('os').cpus().length;

// if (cluster.isMaster) {
//     // Fork workers
//     for (var i = 0; i < numCPUs * 2; i++) {
//         cluster.fork();
//     }
//     cluster.on('exit', function (worker, code, signal) {
//         console.log('worker ' + worker.process.pid + ' died');
//     });
// } else {
//     // Workers can share any TCP connection
//     // In this case its a HTTP server 
//     http.createServer(function (req, res) {
//         res.writeHead(200);
//         res.end("hello world\n");
//     }).listen(8000);
//     console.log("server " + process.pid)
// }
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/mern-starter');

var records_Schema = mongoose.Schema({
  openID: String,
  unionID: String,
  content: String,
  step: Number,
  stepAnswer: String,
  stepResult: String
});

var records = mongoose.model('helloworld_records', records_Schema);


records.find({
}, (err, docs) => {
    var num = 0
    // console.log(docs, docs.length)
    for(var i = 0; i < docs.length; i++){
        var time = new Date(Number(parseInt(docs[i]._id.toString().substr(0, 8), 16).toString() + '000'))

        if(time > new Date(2019,3,30,6,0,0) && time < new Date(2019,3,30,13,0,0)){
            num++
            console.log(docs[i], num)
        }
    }
    console.log("qqq")
})